package net.homeftp.heimo.adaptor;

import java.util.List;

import net.homeftp.heimo.model.Sample;
import net.homeftp.heimo.R;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.GridView;

public class GridBottonAdapter extends BaseAdapter {
	private Context mContext;
	private List<Sample> list;

	public GridBottonAdapter(Context c, List<Sample> sampleList) {
		mContext = c;
		this.list = sampleList;
	}

	public int getCount() {
		return list.size();
	}

	public Sample getItem(int position) {
		return list.get(position);
	}

	public long getItemId(int position) {
		return position;
	}

	// create a new ImageView for each item referenced by the Adapter
	public View getView(int position, View convertView, ViewGroup parent) {
		Button btnCtrl;
		if (convertView == null) { // if it's not recycled, initialize some
									// attributes
			btnCtrl = new Button(mContext);
			btnCtrl.setLayoutParams(new GridView.LayoutParams(85, 85));
			btnCtrl.setPadding(8, 8, 8, 8);
		} else {
			btnCtrl = (Button) convertView;
		}
		Sample s = getItem(position);
		btnCtrl.setText(s.getSampleName());
		fnSetStyle(btnCtrl,position);
		return btnCtrl;
	}

	private void fnSetStyle(Button btnCtrl, int pos) {
		btnCtrl.setFocusable(false);
		btnCtrl.setClickable(false);
		btnCtrl.setPadding(10, 10, 10, 10);
		
		int res = R.xml.btn_selector_green;
		if(pos>0){
			if(pos%2==0){
				res = R.xml.btn_selector_yellow;
			}
			if(pos%3==0){
				res = R.xml.btn_selector_red;
			}
			if(pos%5==0){
				res = R.xml.btn_selector_blue;
			}
			if(pos%7==0){
				res = R.xml.btn_selector_purple;
			}
			if(pos%10==0){
				res = R.xml.btn_selector_black;
			}
		}
		btnCtrl.setBackgroundResource(res);
//		btnCtrl.setBackgroundColor(R.xml.btn_selector_black);
	}
}